import { IsString, IsNotEmpty, MaxLength, IsOptional } from "class-validator";
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
import { QueryDto } from "/@/common/dto/query.dto";

export class AddGoodsTypeDto {
  @ApiProperty({ description: "商品分类名称" })
  @MaxLength(50, { message: "name长度不超过50" })
  @IsString({ message: "不是有效的name" })
  @IsNotEmpty({ message: "name不能为空" })
  readonly name: string;

  @ApiProperty({ description: "商品分类图片" })
  @MaxLength(225, { message: "url长度不超过225" })
  @IsString({ message: "不是有效的url" })
  @IsNotEmpty({ message: "url不能为空" })
  readonly url: string;

  @ApiProperty({ description: "商品分类父级id" })
  readonly pid: number;

  @IsOptional()
  @ApiPropertyOptional({ description: "商品分类父级名称" })
  @IsString()
  pname: string;

  @IsOptional()
  @ApiPropertyOptional({ description: "备注" })
  @IsString()
  readonly des: string;
}

export class DelGoodsTypeDto {}
export class EditGoodsTypeDto extends AddGoodsTypeDto {
  @ApiProperty({ description: "商品分类id" })
  readonly id: number;
}
export class GetGoodsTypeDto extends QueryDto {
  @IsOptional()
  @ApiPropertyOptional({ description: "商品分类名称" })
  @MaxLength(50, { message: "name长度不超过50" })
  @IsString({ message: "不是有效的name" })
  @IsNotEmpty({ message: "name不能为空" })
  readonly name: string;

  @IsOptional()
  @ApiPropertyOptional({ description: "商品分类id" })
  readonly id: number;

  @IsOptional()
  @ApiPropertyOptional({ description: "商品分类父级id" })
  readonly pid: number;

  @IsOptional()
  @ApiPropertyOptional({ description: "备注" })
  @IsString()
  readonly des: string;
}

export class GetGoodsTypeByPidDto {
  @ApiProperty({ description: "商品分类父级id" })
  readonly pid: number;

  @IsOptional()
  @ApiPropertyOptional({ description: "是否反选" })
  @IsString()
  readonly reverse: boolean;
}
